const { toUrl,globalData,msgLoading } = getApp();
import { request } from "@/utils/request";
Page({
  toUrl,
  data: {
    globalData,
    privierUrl: "",
    image: [],
    prviewImg:[],
    content:''
  },
  getLen(){
    let len = this.data.prviewImg 
    if (len.length >= 6) {
      wx.showToast({
        icon:'error',
        title: '最多上传6张',
      })
      return
    }
  },
  changePhoto(e) {
    console.log(111);
    let { img, url } = e.detail;
    console.log(e);
    let list = this.data.prviewImg 
   
    list.push(img)
    this.setData({
      privierUrl: img,
      image: list,
    });
  },
  close(e) {
    console.log(e);
    const index = e.currentTarget.dataset.index
    const imgList = this.data.image
    imgList.splice(index,1)
    this.setData({
      image: imgList
    })
    console.log(this.data.image)
},
  receipt() {
    //提交小票
    if (this.data.image == "") {
      wx.showToast({
        title: "请上传图片",
        icon:'error'
      });
      return;
    }

    let data = {
      image: this.data.image.join(',')
    };
    request("integral/receipt", { data }).then((res) => {
      wx.showToast({
        title: "提交成功",
      });
      this.setData({
        image:[],
        prviewImg:[]
      })
    });
  },
  preview(e){
    console.log(e);

    let {index} = e.currentTarget.dataset
    let Imglist = this.data.image
    wx.previewImage({
      current: Imglist[index], // 当前显示图片的http链接
      urls: Imglist // 需要预览的图片http链接列表
    })
  },
  inIt(){
    msgLoading()
    let data = {
      id:8
    };
    request("currency/getarticle", { data }).then((res) => {
      console.log(res.data);
      let {content,title} = res.data

      let zhengze = new RegExp('<img','g')
      let contents= content.replace(zhengze, '<img style="width:100%;height:auto;display:block;margin:10px 0;" ') 
      this.setData({
        content:contents,
    })
      // let 
    }).finally(()=>{
      wx.hideLoading()
    })

  },
  onLoad(options) {
    this.inIt()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});